{extend name='template/base'}{/extend}
{block name='style'}{/block}
{block name='script'}{/block}
{block name='content'}

<div class="row">
    <div class="col-xs-12">
        <div class="box-body">
            <div class="row">
                <div class="col-xs-3">
                    <div class="input-group col-xs-12">
                        <span class="input-group-addon">关键字</span>
                        <input type="text" class="form-control" id="keyword" placeholder="姓名、微信、电话"/>
                    </div>
                </div>
                <div class="col-xs-3">
                    <div class="input-group col-xs-12">
                        <span class="input-group-addon">注册时间</span>
                        <input class="form-control datetimepicker" type="text" name="begindate"
                               id="begindate" placeholder="起始日期"/>
                        <span class="input-group-addon" style="width:1em;">至</span>
                        <input class="form-control datetimepicker" type="text" name="enddate" id="enddate"
                               placeholder="截止日期"/>
                    </div>
                </div>
                <div class="col-xs-1">
                    <button type="button" class="btn btn-primary" id="btn_search"><i
                            class="glyphicon glyphicon-search"></i> 搜索
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-body">
                <table id="table"
                       data-toggle="table"
                       data-striped ="true"
                       data-query-params = "requestParam"
                       data-side-pagination="server"
                       data-pagination="true"
                       data-id-field="id"
                       data-url="{:url('ShopDelivery/index_data')}"
                >
                    <thead>
                    <tr>
                        <th data-field="account_id">ID</th>
                        <th data-field="account_name">姓名</th>
                        <th data-field="wechat">微信号</th>
                        <th data-field="mobile">电话</th>
                        <th data-field="update_time" data-formatter="formatTime">设置配送员日期</th>
                        <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents" >操作</th>
                    </tr>
                    </thead>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->

    </div><!-- /.col -->
</div><!-- /.row -->
{/block}
{block name='script_extra'}
<script>
    var verify_data_url="{:url('ShopDelivery/verify')}";
    var edit_data_url="{:url('ShopDelivery/edit')}";
    var delete_data_url="{:url('ShopDelivery/delete')}";
</script>
<script>
    $('.datetimepicker').datetimepicker({
        format: "Y-m-d",
        lang: 'ch',
        timepicker: false
    });
</script>
<script>
    // <editor-fold defaultstate="collapsed" desc="格式化url">
    function urlFormat(url) {
        if( url.indexOf('.html')){
            url=url.replace('.html','')
        }
        return url;
    }
    // </editor-fold>


    $("#sel_status").on('change', function () {
        $('#table').bootstrapTable('refresh');
    })

    $("#sel_type").on('change', function () {
        $('#table').bootstrapTable('refresh');
    })

    //搜索按钮事件
    $("#btn_search").on('click', function () {
        $('#table').bootstrapTable('refresh');
    })


    var temp = {};
    function requestParam(params) {
        temp = {
            limit: params.limit, //页面大小
            offset: params.offset, //页码
            order: params.order,
            sort: params.sort,
            search: $("#keyword").val(),
            status: $("#sel_status").val(),
            type: $("#sel_type").val(),
            begindate: $("#begindate").val(),
            enddate: $("#enddate").val()
        };
        return temp;
    }


    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click',function () {
        layer_open('添加',add_data_url)
    });
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="操作按钮">
    function formatOperate(value,row,index){
        return [
            '<button class="btn btn-success btn-xs row_edit" href="javascript:void(0)">',
            '<i class="fa fa-edit"></i> 修改',
            '</button>&nbsp;',
            '<button class="btn btn-danger btn-xs row_delete" href="javascript:void(0)">',
            '<i class="fa fa-trash"></i> 删除',
            '</button>'
        ].join('');
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {

        'click .row_verify': function (e, value, row, index) {
            layer_open('审核',urlFormat(verify_data_url)+"/store_id/"+row.store_id+"/account_id/"+row.account_id);
        },
        'click .row_edit': function (e, value, row, index) {
            layer_open('更改信息',urlFormat(edit_data_url)+"/store_id/"+row.store_id+"/account_id/"+row.account_id);
        },
        'click .row_delete': function (e, value, row, index) {
            layer.confirm('你确定要删除该选项吗？',{btn:['确定','取消']},function () {
                $.ajax({
                    dataType:'json',
                    data:{id:row.id},
                    url:delete_data_url,
                    success:function (res) {
                        if(res.success){
                            layer.msg(res.message, {time: 1000},function () {
                                $('#table').bootstrapTable('refresh');
                            });
                        }else{
                            layer.alert(res.message);
                        }
                    }
                })
            })
        },
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="时间格式化">
    function formatTime(value) {
        if(value){
            var date = new Date(parseInt(value) * 1000);
            Y = date.getFullYear() + '-';
            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
            D = (date.getDate() + 1 < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
            h = (date.getHours() + 1 < 10 ? '0' + (date.getHours()) : date.getHours()) + ':';
            m = (date.getMinutes() + 1 < 10 ? '0' + (date.getMinutes()) : date.getMinutes()) + ':';
            s = (date.getSeconds() + 1 < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
            return Y + M + D + h + m + s;
        }

    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="状态格式化">
    function formatStatus(value) {
        switch(value){
            case 0:
                return '<i class="fa fa-check-circle text-green" title="正常">正常</i>';break;
            case 1:
                return '<i class="fa fa-minus-circle text-yellow" title="锁定">锁定</i>';break;
        }

    }
    function formatCHeckStatus(value) {
        switch(value){
            case 0:
                return '<i class="fa fa-minus-circle text-yellow" title="未审核">未审核</i>';break;
            case 1:
                return '<i class="fa fa-check-circle text-green" title="审核通过">审核通过</i>';break;
            case 2:
                return '<i class="fa fa-check-circle text-black" title="审核不通过">审核不通过</i>';break;

        }

    }


    // </editor-fold>

</script>
{/block}